package com.ttx.algorithm.leetcode.linkedlist;

/**
 * https://leetcode.com/problems/reverse-linked-list/
 *
 * <p> 单链表反转
 *
 * @author TimFruit
 * @date 19-1-1 下午11:32
 */
public class P206ReverseLinkedList {

    /*
    Example:

    Input: 1->2->3->4->5->NULL
    Output: 5->4->3->2->1->NULL

     */


    public ListNode reverseList(ListNode head) {

        ListNode p=null;
        ListNode newHead=null;
        while(head != null){
            p=head.next;
            head.next=newHead;
            newHead=head;
            head=p;
        }
        return newHead;
    }



}



